package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MakeFriendManager;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.Friend;
import com.itheima.service.mongo.FriendService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.List;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    // 查询今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest() {
        return makeFriendManager.findTodayBest();
    }

    // 查询推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return makeFriendManager.findRecommendUserVoByPage(pageNum, pageSize);
    }

    //查询推荐用户卡片
    @GetMapping("/tanhua/cards")
    public ResponseEntity findRecommendCards() {
        //调用manager
       return makeFriendManager.findRecommendCards();
    }

    // 佳人详情
    @GetMapping("/tanhua/{jiarenId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long jiarenId) {
        return makeFriendManager.findPersonalInfo(jiarenId);
    }


    // 判断你是否喜欢对方
    @GetMapping("/users/{jiarenId}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable Long jiarenId){

        return makeFriendManager.alreadyLove(jiarenId);

    }


    // 查询历史访客
    @GetMapping("/movements/visitors")
    public ResponseEntity visitors(){
        return makeFriendManager.visitors();
    }

    // 上报地理位置
    @PostMapping("/baidu/location")
    public void saveLocation(@RequestBody Map<String,String> param){
        System.out.println("用户上传地理坐标："+param);

        // 必须用包装类接收
        Double latitude = Double.parseDouble(param.get("latitude"));
        Double longitude = Double.parseDouble(param.get("longitude"));
        String addrStr = param.get("addrStr");
        // 调用manager
        makeFriendManager.saveLocation(latitude,longitude,addrStr);
    }


    // 搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNearUser(String gender,Long distance){
        // 调用manager
        return makeFriendManager.searchNearUser(gender,distance);
    }

    // 查看对方的陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam(value = "userId") Long jiarenId){
        // 调用manager
        return makeFriendManager.strangerQuestions(jiarenId);
    }

    //左滑不喜欢
    @GetMapping("/tanhua/{userId}/unlove")
    public void unLove(@PathVariable String userId) {
        //调用manager
        makeFriendManager.unLove(userId);
    }
    //右滑喜欢
    @GetMapping("/tanhua/{userId}/love")
    public void love(@PathVariable String userId) {
        //调用manager
        makeFriendManager.love(userId);
    }

    //互相喜欢，喜欢，粉丝
    @GetMapping("/users/counts")
    public ResponseEntity findFanLoveLike() {
        //调用manager
       return makeFriendManager.findFanLoveLike();
    }

    //根据类型查询所需要的分页数据（查询我喜欢的，我的粉丝，相互喜欢以及看我的人）
    @GetMapping("/users/friends/{type}")
    public ResponseEntity findFriendsType(@PathVariable String type,
                                          @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {

        //调用manager
        return makeFriendManager.findFriendsType(type, pageNum, pageSize);
    }

    //粉丝喜欢
    @PostMapping("/users/fans/{likeUserId}")
    public void fanSave(@PathVariable Long likeUserId) {
        //调用manager方法
        makeFriendManager.fanSave(likeUserId);

    }



    //粉丝不喜欢
    @DeleteMapping("/users/like/{likeUserId}")
    public void fanDelete(@PathVariable Long likeUserId) {

        //调用manager方法
        makeFriendManager.fanDelete(likeUserId);
    }


}
